import DB.PDBC as db
from sqlalchemy import text

if __name__ == '__main__':
    con = db.connect()
    sql = """
            select * from (
        select a.RECOGNITION_CODE , (select c.code_name from  system_code c where  c.CODE_GROUP = 3 and c.CODE_KEY in (SELECT b.GROUP_STATE from meitu_code b where b.GROUP_ID = a.IMAGE_GROUP) limit 1) as state_name from face_table a where a.`NAME` like 'G:%' and (SELECT count(1) from meitu_code e where e.GROUP_ID = a.IMAGE_GROUP  ) = 1 
        ) f  
        where f.state_name not like '%网站'
    """
    res = con.execute(text(sql)).fetchall()
    for row in res:
        print(row[0])
        print(row[1])
        con.execute(text("update face_table set name = :name where RECOGNITION_CODE = :code"),{"name":row[1],"code":row[0]})
        con.commit()
    con.close()